package com.zhuoli.service.springboot.task.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: zhuoli
 * @Date: 2018/9/6 10:06
 * @Description:
 */
@Component
@Slf4j
public class SpringTask {
    @Async
    @Scheduled(cron = "0/1 * * * * *")
    public void scheduled1() throws InterruptedException {
        log.info("scheduled1 每1秒执行一次：{}", LocalDateTime.now());
        Thread.sleep(3000);
    }

    @Async
    @Scheduled(fixedRate = 1000)
    public void scheduled2() throws InterruptedException {
        log.info("scheduled2 每1秒执行一次：{}", LocalDateTime.now());
        Thread.sleep(3000);
    }

    @Scheduled(fixedDelay = 3000)
    public void scheduled3() throws InterruptedException {
        log.info("scheduled3 上次执行完毕后隔3秒继续执行：{}", LocalDateTime.now());
        Thread.sleep(5000);
    }
}
